﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Setting_DeptSort : SessionPage
{
	LogicLayer mgr = new LogicLayer();
	protected string pid = "", tip = "";

	protected void Page_Load(object sender, EventArgs e)
	{
		//检查权限
		this.VerifyFunction("setting");

		pid = Request.QueryString["pid"] + "";

		if (IsPostBack)
		{
			System.Collections.Hashtable hash = new System.Collections.Hashtable();
			string key = string.Empty;
			for (int i = 0; i < Request.Form.Count; i++)
			{
				key = Request.Form.GetKey(i);
				if (key.StartsWith("txt_"))
				{
					hash.Add(key.Replace("txt_", ""), Request.Form[i]);
				}
			}
			if (mgr.SortDept(hash))
				Response.Redirect("departments.aspx?id=" + pid);
			else
				tip = "保存失败!";
		}

	}

	protected void WriteTableData()
	{
		List<SYS_Department> deptList = mgr.ListDeptByParent(pid);
		if (deptList == null)
			return;

		foreach (SYS_Department dept in deptList)
		{
			Response.Write("<tr>");

			Response.Write("<td nowrap>");
			Response.Write(dept.DeptName);
			Response.Write("</td>");

			Response.Write("<td >");
			string eleName = "txt_" + dept.DeptID;
			Response.Write("<input type=\"text\" id=\"" + eleName + "\" name=\"" + eleName + "\" value=\"" + dept.DeptNo + "\" />");
			Response.Write("</td>");

			Response.Write("</tr>");
		}
	}
}